package com.wmyg.antifake.entity;

import lombok.Data;
import org.hibernate.annotations.NotFound;
import org.hibernate.annotations.NotFoundAction;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import javax.persistence.*;
import java.util.*;

/**
 * @author 王卓逸
 * @program TODO
 * @description TODO
 * @create 2019-05-05
 */
@Entity
@EntityListeners(AuditingEntityListener.class)
@Data
@Table(name = "bk_record")
public class Record {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "record_id")
    private Integer recordId;

    @Column(name = "record_name")
    private String recordName;

    @ManyToOne(cascade = {CascadeType.PERSIST, CascadeType.REFRESH}, fetch = FetchType.EAGER)
    @NotFound(action = NotFoundAction.IGNORE)
    @JoinColumn(name = "product_id")
    private Product product;

    @ManyToOne(cascade = {CascadeType.PERSIST, CascadeType.REFRESH}, fetch = FetchType.EAGER)
    @NotFound(action = NotFoundAction.IGNORE)
    @JoinColumn(name = "factory_id")
    private Factory factory;

    @ManyToOne(cascade = {CascadeType.PERSIST, CascadeType.REFRESH}, fetch = FetchType.EAGER)
    @NotFound(action = NotFoundAction.IGNORE)
    @JoinColumn(name = "origin_id")
    private ProductOrigin origin;

    @Column(name = "batch")
    private String batch;

    @Column(name = "enter_case")
    private Integer enterCase;

    @Column(name = "enter_box")
    private Integer enterBox;

    @Column(name = "enter_pack")
    private Integer enterPack;

    @Column(name = "total_box")
    private Integer totalBox;

    @Column(name = "total_pack")
    private Integer totalPack;

    @Column(name = "total")
    private Integer total;

    @Column(name = "excel_name")
    private String excelName;

    @Column(name = "excel_md5")
    private String excelMd5;

    @Column(name = "pay_state")
    private Integer payState = 0; //0.未支付 1.已生成微信预支付订单 2.已生成支付宝预支付订单 3.微信支付宝均生成预支付订单 4.支付完成，生成中 5.生成完毕 6.已关闭

    @Column(name = "unit_price")
    private Integer unitPrice;

    @Column(name = "total_price")
    private Integer totalPrice;

    @Column(name = "discount")
    private Integer discount;

    @Column(name = "final_price")
    private Integer finalPrice;

    @Column(name = "wxpay_id")
    private String wxpayId;

    @Column(name = "alipay_id")
    private String alipayId;

    @Column(name = "wxpay_code_url")
    private String wxpayCodeUrl;

    @Column(name = "alipay_code_url")
    private String alipayCodeUrl;

    @Column(name = "wxpay_prepay_id")
    private String wxpayPrepayId;

    @OneToMany(fetch = FetchType.EAGER, cascade = {CascadeType.ALL})
    @NotFound(action = NotFoundAction.IGNORE)
    @JoinColumn(name = "record_id")
//    @OrderBy(value = "download_time desc")
    private Set<DownloadInfo> downloadInfos = new HashSet<>();

    @CreatedDate
    @Column(name = "create_time")
    private Date createTime;

    @LastModifiedDate
    @Column(name = "modify_time")
    private Date modifyTime;

}
